function selectUserById(userId, callback) {
    $.ajax({
        type: 'post',
        url: '/user/selectUserById',
        data: {
            userId: userId
        }
        ,success: function(result) {
            if(result.code === "SUCCESS") {
                callback(result.data);
            }else{
                alert(result.errMsg);
            }
        }
        ,error: function(error) {
            if (error != null && error.status === 401) {
                console.log("未登录");
            } else {
                alert("内部错误");
            }
        }
    });
}

function updateUserAgeById(userId, age) {
    $.ajax({
        type: 'post',
        url: 'user/updateUserById',
        data: {
            userId: userId,
            age: age
        }
        , success: function (result) {
            if(result.code === "SUCCESS") {
                console.log("修改成功");
            }else{
                alert(result.errMsg);
            }
        }
        , error: function (error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}

function updateUserGenderById(userId, gender) {
    $.ajax({
        type: 'post',
        url: 'user/updateUserById',
        data: {
            userId: userId,
            gender: gender
        }
        , success: function (result) {
            if(result.code === "SUCCESS") {
                console.log("修改成功");
            }else{
                alert(result.errMsg);
            }
        }
        , error: function (error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}


function updateUserFieldById(userId, fieldName, value, callback=null) {
// 创建一个空对象用于存储数据
    let data = {
        userId: userId
    };
    // 动态添加要修改的字段和对应的值
    data[fieldName] = value;

    $.ajax({
        type: 'post',
        url: 'user/updateUserById',
        data: data,
        success: function (result) {
            if (result.code === "SUCCESS") {
                if(callback != null) {
                    callback(result.data);
                }
                console.log("修改成功");
            } else {
                alert(result.errMsg);
            }
        },
        error: function (error) {
            if (error != null && error.status === 401) {
                alert("请先登录");
                location.href = "/login.html";
            } else {
                alert("内部错误");
            }
        }
    });
}